package com.jy.admin.rest;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.fqgj.base.services.redis.RedisClient;
import com.fqgj.common.utils.MD5;
import com.jy.admin.jobs.DndCheckJob;
import com.jy.admin.rest.request.WhatsappMsgRequest;
import com.jy.bo.common.conf.api.ApiResponse;
import com.qianli.cashmama.product.facade.ProductFacade;
import com.jy.admin.annotations.AdminSignIgnore;
import com.jy.admin.auth.anno.VisitorAccessible;
import com.jy.bo.common.conf.config.FileConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: binary (mr.vencnet@gmail.com)
 * Date: 2020-06-02
 * Time: 17:18
 */
@RestController
public class OkController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OkController.class);

    @Autowired
    private RedisClient redisClient;

    @Autowired
    private FileConfigUtil fileConfigUtil;

    @Autowired
    private ProductFacade productFacade;

    @Autowired
    private DndCheckJob dndCheckJob;


    @NacosValue(value = "${chrome.driver.path:/home/java/dc-ms/chromedriver}", autoRefreshed = true)
    private String chromeDriverPath;


    @AdminSignIgnore
    @RequestMapping("/ok")
    @VisitorAccessible
    public String ok() {
        redisClient.set("aa", "1111");
        return redisClient.get("aa");
    }


    @AdminSignIgnore
    @VisitorAccessible
    @RequestMapping("/ok1")
    public String ok1(Integer x, Integer y, Integer w, Integer h) {

        System.setProperty("webdriver.chrome.driver", chromeDriverPath);

//        // Initialize browser
//        System.setProperty("webdriver.chrome.whitelistedIps", "");
//        ChromeOptions chromeOptions = new ChromeOptions();
//        //关闭窗口
//        chromeOptions.addArguments("--headless");
//        chromeOptions.addArguments("--window-size=2560,1980");
//        chromeOptions.addArguments("--disable-dev-shm-usage");
//
//        //无痕浏览
//        chromeOptions.addArguments("--incognito");
//        chromeOptions.addArguments("--whitelisted-ips");
//        chromeOptions.addArguments("--no-sandbox");
//        WebDriver driver = new ChromeDriver(chromeOptions);
//        driver.get("http://dndsearch.in/index.php");
//
//        LOGGER.info("== 获取验证码 开始 ==");
////        String verifyCode = getVerifyCode(driver);
//        dndCheckJob.getVerifyCode(driver,x, y,
//                w, h);

        List<String> mobiles = new ArrayList<>();
        mobiles.add("8050843289");
        try {
            dndCheckJob.getDNDMobileList(mobiles);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "aa";
    }

    @AdminSignIgnore
    @RequestMapping("/logok")
    @ResponseBody
    @VisitorAccessible
    public String logok() {
        LOGGER.info("testok,AAA111111222222333333," + fileConfigUtil.isServerTest());
        return "logok";
    }

    public static void main(String[] args) {
        String s = MD5.md5("123456");
        System.err.println(s);
    }
}
